package kr.co.doriclassic.pro10;

import java.util.Scanner;

class Cinema {
	private int iTicket;
	private int iCount;
	private String[] iSeat;

	public Cinema() {
		iTicket = 0;
		iSeat=new String[10];
		for(int i=0;i<iSeat.length;i++){
			iSeat[i]="0";
		}
		iCount = 0;
	}	
	public void printSeat() {
		System.out.println("--------------------------------");
		for(int i=0;i<iSeat.length;i++){
			System.out.printf("%2d ",i+1);
		}
		System.out.println();
		System.out.println("--------------------------------");
		for(int i=0;i<iSeat.length;i++){
			System.out.printf("%2s ",iSeat[i]);
		}
	}	
	public void setSeat(){
		Scanner sc = new Scanner(System.in);		
		do {
			
			try {
				printSeat();
				System.out.println();
				
				System.out.print("몇 번째 좌석을 예약하시겠습니까?(1`10):");
				iCount=sc.nextInt();
				
					System.out.print("좌석을 예매하시겠습니까?(1 : 예매 / 0 : 종료):");
					iTicket=sc.nextInt();
					
					if(iTicket!=0){
						if(iSeat[iCount-1].equalsIgnoreCase("0")){
							iSeat[iCount-1]="1";						
						}
						else{
							System.out.println("이미 예약되어 있습니다.");
							
						}					
					}
					else{
						System.out.println("종료합니다.");
						break;
					}	
			} catch (ArrayIndexOutOfBoundsException e) {
				System.out.println("좌석은 1부터 10까지 선택 가능합니다. 다시 선택해주세요.");
			}				
		} while (iTicket!=0);
	}
}

public class CinemaTest{
	public static void main(String[] args) {
		Cinema ticket = new Cinema();
		ticket.setSeat();
	}	
}
